<?php

 
Zend_Loader::loadClass("BaseDBRows");
Zend_Loader::loadClass("DocumentLibrary");
class DocumentLibraries extends BaseDBRows
{
	protected function setUp()
	{
		$this->_tableName = DocumentLibrary::_tablename;
	}	
	
	public function getDocumentsByOrgType($orgType) {
	
		Zend_Loader::loadClass("Document");
		Zend_Loader::loadClass("CodesUtility");
		Zend_Loader::loadClass("QueryCreator");
		
		$query = new QueryCreator();
		// $query->addSelect(" dl.*, concat('file:',replace(d.link,'\\\','\/')) link, d.title, d.description, ifnull(date_updated,d.date_created) date_uploaded, instr(lower(d.title),'map') map ");
		$query->addSelect(" dl.*, d.link, d.title, d.description, ifnull(date_updated,d.date_created) date_uploaded, instr(lower(d.title),'map') map ");
		// $query->addSelect(" dl.*, concat(replace(d.link,'\\\','\\\')) link, d.title, d.description, ifnull(date_updated,d.date_created) date_uploaded, instr(lower(d.title),'map') map ");
		$query->addFrom($this->_tableName . " dl ");
		$query->addJoin(" left join " . Document::_tablename . " d on d.id = dl.id ");
		
		// echo $orgType;die();
		switch($orgType) {
			case CodesUtility::USER_TYPE_EXPORTER:
				$query->addWhere(" dl.display_exporter = 1 ");
				break;
			case CodesUtility::USER_TYPE_IMPORTER:
				$query->addWhere(" dl.display_importer = 1 ");
				break;
		}
		
		$db = DBCon::instance();
		 //echo  $query->createSQL();die();
		$result = $db->executeQuery($query->CreateSQL());
		return $result;
		
	}
	
}
?>